home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks97 / CrashBurn.sit / Crash & Burn / source code / CrashBurnPatchMain.cpp next >
C/C++ Source or Header  |  1997-06-27  |  2KB  |  96 lines

  1. #include "patches.h"
  2. #include <traps.h>
  3. #include <lowmem.h>
  4.  
  5. static asm long*    GetOldDebugUtilStorage()
  6. {
  7.     lea        _oldDebugUtilStorage,a0
  8.     rts
  9. _oldDebugUtilStorage:
  10.     dc.l    0x00000000
  11. }
  12.  
  13. static asm long* GetCountStorage()
  14. {
  15.     lea        _countStorage,a0
  16.     rts
  17. _countStorage:
  18.     dc.l    0x00000000
  19. }
  20.  
  21.  
  22. static asm long* GetProcStorage()
  23. {
  24.     lea        _procStorage,a0
  25.     rts
  26. _procStorage:
  27.     dc.l    0x00000000
  28. }
  29.  
  30.  
  31.  
  32. static long    Poll(short selector)
  33. {
  34.     long        continueQ = true;
  35.     
  36.     
  37.     long*        count = GetCountStorage();
  38.     
  39.     if(selector == 3){
  40.  
  41.         long*    procStore = GetProcStorage();
  42.         ProcPtr    p = (ProcPtr)*procStore;
  43.         
  44.         if(p != NULL){
  45.             (*p)();
  46.         }
  47.     }
  48.     
  49.     return continueQ;
  50. }
  51.  
  52.  
  53. static asm void newDebugUtil()
  54. {
  55.     subq.l    #4,a7                        // reserve space for old trap address
  56.     move.l    a0,-(a7)                    // save a0
  57.     movem.l    a1-a5/d0-d7,-(a7)            // save everything else
  58.     
  59.     move.w    d0,-(a7)
  60.     jsr        Poll
  61.     addq.l    #2,a7
  62.     tst.w    d0
  63.     bne.s    _Continue
  64.     
  65.     movem.l    (a7)+,a1-a5/d0-d7
  66.     move.l    (a7)+,a0
  67.     addq.l    #4,a7
  68.     rts
  69.     
  70. _Continue:
  71.     
  72.  
  73.     movem.l    (a7)+,a1-a5/d0-d7            // restore registers
  74.     
  75.     jsr        GetOldDebugUtilStorage        // get original trap address storage in a0
  76.     move.l    (a0),a0                        // get original trap address value into a0
  77.     move.l    a0,4(a7)                    // stuff old trap onto stack
  78.     move.l    (a7)+,a0                    // restore original a0
  79.     rts                                    // rts to jump to old trap.
  80. }
  81.  
  82.  
  83.  
  84. pascal void main(ProcPtr inIdleProc)
  85. {
  86.  
  87.     long*        procStore = GetProcStorage();
  88.     *procStore = (long)inIdleProc;
  89.             
  90.     long*        debugUtilStorage = GetOldDebugUtilStorage();
  91.     *debugUtilStorage = PatchTrap(_DebugUtil,(long)newDebugUtil);
  92.  
  93.         
  94. }
  95.  
  96.